package com.shanzmoo.db.order.entity.vo;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.shanzmoo.db.order.entity.OutletOrderDetailEntity;
import com.shanzmoo.db.order.entity.OutletOrderEntity;
import com.shanzmoo.db.order.entity.dto.OutletOrderDetailInfoDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 门店订单详情
 * @author: Gzhao 2020/12/14
 */
@Data
@ApiModel("门店订单详情")
public class OutletOrderInfoVo implements Serializable {

    private static final long serialVersionUID = 1758L;

    @ApiModelProperty(value = "订单Id")
    private Integer orderId;

    @ApiModelProperty(value = "订单号")
    private String orderNo;

    @ApiModelProperty(value = "会员id")
    private Integer memberId;

    @ApiModelProperty(value = "会员名称")
    private String memberName;

    @ApiModelProperty(value = "折扣")
    private BigDecimal discount;

    @ApiModelProperty(value = "发货类型:0-自提，1-物流")
    private Integer deliveryType;

    @ApiModelProperty(value = "结算方式：是否月结")
    private Boolean monthly;

    @ApiModelProperty(value = "订单状态: 0-新开单，1-刷机中，2-待取货，3-已完结，4-已结算, 9-已作废")
    private Integer status;

    @ApiModelProperty(value = "订单金额订单金额（单位元）")
    private BigDecimal amount;

    @ApiModelProperty(value = "支付状态: false-未支付，true-已支付）")
    private Boolean payStatus;

    @ApiModelProperty(value = "支付单号")
    private String payNo;

    @ApiModelProperty(value = "支付方式")
    private String payType;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "支付完成时间")
    private LocalDateTime payFinishTime;

    @ApiModelProperty(value = "收件人")
    private String consignee;

    @ApiModelProperty(value = "收件人所在省市区")
    private String consigneeDistrict;

    @ApiModelProperty(value = "收件人手机")
    private String consigneeMobile;

    @ApiModelProperty(value = "收件人详细地址", example = "国贸309号")
    private String consigneeAddress;

    @ApiModelProperty(value = "预计完成时间")
    private LocalDate expectFinishDate;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "实收金额（单位元）")
    private BigDecimal receiveAmount;

    @ApiModelProperty(value = "折扣金额")
    private BigDecimal discountAmount;

    @ApiModelProperty(value = "优惠金额（单位元）")
    private BigDecimal abatement;

    @ApiModelProperty(value = "优惠原因")
    private String abatementReason;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "订单创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "订单明细")
    private List<OutletOrderDetailInfoDto> orderDetails;

    public static OutletOrderInfoVo create(OutletOrderEntity order, List<OutletOrderDetailEntity> detailList) {
        OutletOrderInfoVo orderInfoVo = JSON.parseObject(JSON.toJSONString(order), OutletOrderInfoVo.class);
        orderInfoVo.setOrderDetails(OutletOrderDetailInfoDto.createList(detailList));
        orderInfoVo.setOrderId(order.getId());

        return orderInfoVo;
    }
}
